package com.cloud.school.bus.teacherhelper.protocol.classmanage;

import org.apache.http.Header;
import org.json.JSONObject;

import com.cloud.school.bus.teacherhelper.entitys.Student;
import com.cloud.school.bus.teacherhelper.protocol.baseresponse.BaseJsonHttpResponse;

public class AddStudentResponse extends BaseJsonHttpResponse {

	protected Student student = null;

	@Override
	public void onSuccess(int statusCode, Header[] headers,
			String responseString) throws Throwable {
		if ("1".equals(code)) {
			student = new Student();
			JSONObject mainJsonObject = new JSONObject(responseString);
			student.key = mainJsonObject.optString("key", "");
			if ("1".equals(student.key)) {
				// 1 为手机号存在关联学生
				student.student = mainJsonObject.optString("student", "");
				student.parentid = mainJsonObject.optString("parentid", "");
				student.ismainid = mainJsonObject.optString("ismainid", "");
				student.releationship = mainJsonObject.optString("releationship", "");
			} else if ("2".equals(student.key)) {
				// 2为不存在关联学生
				JSONObject studentJsonObject = mainJsonObject
						.optJSONObject("student");
				if (null != studentJsonObject) {
					student.parentid = studentJsonObject.optString("parentid",
							"");
					student.username = studentJsonObject.optString("username",
							"");
					student.mobile = studentJsonObject.optString("mobile", "");
					student.birthday = studentJsonObject.optString("birthday",
							"");
					student.studentid = studentJsonObject.optString(
							"studentid", "");
					student.studentno = studentJsonObject.optString(
							"studentno", "");
					student.uid_student = studentJsonObject.optString(
							"uid_student", "");
					student.cnname = studentJsonObject.optString("cnname", "");
					student.enname = studentJsonObject.optString("enname", "");
					student.avatar = studentJsonObject.optString("avatar", "");
					student.filesize = studentJsonObject.optString("filesize",
							"");
					student.sex = studentJsonObject.optString("sex", "");
					student.orderendtime = studentJsonObject.optString(
							"orderendtime", "");
					student.age = studentJsonObject.optString("age", "");
				}
			}
		}
	}
}
